package com.gyw.myapplication.compare;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * Created by Administrator on 2018/12/7.
 */

public abstract class TableAdapter<CORNER_VH extends TableAdapter.ViewHolder, TOP_CELL_VH extends RecyclerView.ViewHolder,
        GROPU_ROW_VH extends RecyclerView.ViewHolder,LEFT_CELL_VH extends TableAdapter.ViewHolder,CELL_VH extends RecyclerView.ViewHolder,
        SUSPENSION_VH extends TableAdapter.ViewHolder>{

    //表格内容的行数
    public abstract int getCellRows();

    //列数
    public abstract int getCellColumns();

    //左上角制表格
    public abstract CORNER_VH onCreateCornerCellViewHolder(ViewGroup parent);

    public abstract void onBindCornerCellViewHolder(CORNER_VH viewHolder);

    //顶部起始行
    public abstract TOP_CELL_VH onCreateTopCellViewHolder(ViewGroup parent);

    public abstract void onBindTopCellViewHolder(TOP_CELL_VH viewHolder,int columnPosition);

    //可能有分组，也可能没有
    public abstract GROPU_ROW_VH onCreateGroupRowViewHolder(ViewGroup parent);

    public abstract void onBindGroupRowViewHolder(GROPU_ROW_VH viewHolder,int rowPosition);

    //左部起始列
    public abstract LEFT_CELL_VH onCreateLeftCellViewHolder(ViewGroup parent);

    public abstract void onBindLeftCellViewHolder(LEFT_CELL_VH viewHolder,int rowPosition);

    public abstract CELL_VH onCreateCellViewHolder(ViewGroup parent);

    public abstract void onBindCellViewHolder(CELL_VH viewHolder,int columnPosition,int rowPosition);

    /**
     *
     * @param position:table的rows:0开始，不包含表头一行
     * @return  自行根据数据决定，在什么情况下显示GroupView，什么情况下显示CellView
     */
    public abstract boolean isGroupView(int position);


    public abstract SUSPENSION_VH onCreateSuspensionViewHolder();

    /**
     *
     * @param position 当前最上方可见item的position,自行再这个方法编写业务逻辑更新悬浮View的控件值
     */
    public abstract void onBindSuspensionViewHolder(SUSPENSION_VH viewHolder,int position);

    public abstract boolean isPushGroupView(int tableFirstVisibleItemRowPosition);

    public abstract class ViewHolder{
        public final View itemView;

        public ViewHolder(View itemView){
            this.itemView=itemView;
        }
    }


    private DataChangedHelper dataChangedHelper;
    public void registerDataChanged(DataChangedHelper dataChangedHelper){
        this.dataChangedHelper=dataChangedHelper;

    }

    public void notifyDataChanged(){
        dataChangedHelper.notifyDataChanged();
    }

    public interface DataChangedHelper{

        void notifyDataChanged();
    }

}
